package com.fenxiangle.yueding.feature.identification.presnter;

import com.fenxiangle.yueding.entity.bo.IDCardBo;
import com.fenxiangle.yueding.entity.bo.IdentificationBo;
import com.fenxiangle.yueding.feature.identification.contract.IdentificationContract;
import com.fenxiangle.yueding.feature.identification.login.DaggerIdentificationPresenterComponent;
import com.fenxiangle.yueding.feature.login.contract.LoginContract;
import com.suozhang.framework.entity.bo.UserInfoBo;

import org.json.JSONObject;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by Home on 2018/9/9.
 */

public class IdentificationPresenter implements IdentificationContract.Presenter {

    IdentificationContract.View mView;
    @Override
    public void start() {

    }
    @Inject

    IdentificationContract.Model mModel;


    public IdentificationPresenter(IdentificationContract.View mView) {
        this.mView = mView;
        DaggerIdentificationPresenterComponent.create().inject(this);
    }
    @Override
    public void userThirdLogin(List<File> files, Map<String, String> string) {
        mModel.add_basic_authentication(files,string).compose(mView.<String>bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(String s) {
                mView.dismissLoading();
                mView.showLoginSuccess();

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void select_authentication_data(String flag) {
        mModel.select_authentication_data(flag).compose(mView.<IdentificationBo>bindToLife()).subscribe(new Observer<IdentificationBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(IdentificationBo s) {
                mView.dismissLoading();
                mView.showData(s);

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void add_boss_authentication(List<File> files, Map<String, String> string) {
        mModel.add_boss_authentication(files,string).compose(mView.<String>bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(String s) {
                mView.dismissLoading();
                mView.showLoginSuccess();

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void add_uploadIDCard_authentication(String cardNegative, String cardPositive) {
        mModel.add_uploadIDCard_authentication(cardNegative,cardPositive).compose(mView.<IDCardBo>bindToLife()).subscribe(new Observer<IDCardBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(IDCardBo s) {
                mView.dismissLoading();
                mView.showIdentificationData(s);

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void add_uploadBusinessLicense_authentication(String businessLicense) {
        mModel.add_uploadBusinessLicense_authentication(businessLicense).compose(mView.<IDCardBo>bindToLife()).subscribe(new Observer<IDCardBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(IDCardBo s) {
                mView.dismissLoading();
                mView.showIdentificationData(s);

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }
}
